from bs4 import BeautifulSoup

if __name__ == '__main__':
    file = open(file="The Dormouse's story.html", mode="r", encoding="utf-8")
    html = file.read()
    file.close()

    # print(html)

    soup = BeautifulSoup(html, "html.parser")
    # # 使用标签选择器进行查找
    # result = soup.select("title")
    # print(result)

    # 伪类选择器
    # result = soup.select("p:nth-of-type(3)")
    # print(result)

    # 子代选择器
    # result = soup.select("body a")
    # print(result)
    # 直接子代选择器
    # result = soup.select("head > title")
    # print(result)

    # # 兄弟选择器
    # result = soup.select("#link1 ~ .sister")
    # print(result)
    # # 相邻选择器
    # result = soup.select("#link1 + .sister")
    # print(result)

    # # 类选择器
    # result = soup.select(".sister")
    # print(result)

    result = soup.select("#link1, #link2")
    print(result)

    result = soup.select("a[href]")
    print(result)
